package com.tanhua.server.controller;


import com.tanhua.server.service.SettingsServices;
import com.tanhua.vo.PageResult;
import com.tanhua.vo.SettingsVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/settings")
public class SettingsController {
    @Autowired
    private SettingsServices settingsServices;

    /**
     * 通用设置查询
     * @return
     */
    @GetMapping
    public ResponseEntity settings(){
        SettingsVo vo =  settingsServices.settings();
        return ResponseEntity.ok(vo);

    }

    /**
     * 问题设置
     * @param map
     * @return
     */
    @PostMapping("/questions")
    public ResponseEntity questions(@RequestBody Map map){

        //获取参数(设置的问题)
        String content = (String) map.get("content");
        //调用service层传入参数
        settingsServices.saveQuestions(content);
        //返回结果
        return ResponseEntity.ok(null);

    }

    /**
     * 保存设置
     * @param map
     * @return
     */
    @PostMapping("/notifications/setting")
    public ResponseEntity notifications(@RequestBody Map map){
        settingsServices.saveSettings(map);
        return ResponseEntity.ok(null);
    }


    @GetMapping("/blacklist")
    public ResponseEntity blacklist(
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer pagesize){

        PageResult pageResult = settingsServices.blacklist(page,pagesize);

        return ResponseEntity.ok(pageResult);

    }

    @DeleteMapping("/blacklist/{uid}")
    public ResponseEntity delectBlack(@PathVariable("uid") Long blackId ){

        settingsServices.delectBlack(blackId);

        return ResponseEntity.ok(null);
    }
}
